package com.tc.infinitechat.authenticationservice.common;

import com.tc.infinitechat.authenticationservice.exception.BusinessException;
import com.tc.infinitechat.authenticationservice.exception.common.BaseExceptionInterface;
import lombok.Data;
import lombok.experimental.Accessors;
import okhttp3.internal.tls.OkHostnameVerifier;
import org.springframework.http.HttpStatus;

/**
 * @ClassName Result
 * @Author 大马鲛鱼丸Gaga
 * @Description TODO
 * @Date 2025/10/8 14:49
 */
@Data
@Accessors(chain = true)
public class Result<T> {
    // 封装success 属性 用于判断是否请求成功
    private boolean success = true;

    //　封装一个响应信息
    private String message;

    //封装一个响应码
    private String errorCode;

    // 封装存储数据的
    private T data;
    // =================================== 成功响应 ===================================

    public static <T> Result<T> success(){
        Result<T> response = new Result<>();
        response.setSuccess(true);
        return response;
    }

    public static <T> Result<T> success(T data) {
        Result<T> response = new Result<>();
        response.setSuccess(true);
        response.setData(data);
        return response;
    }

    public static <T> Result<T> success(T data, String message) {
        Result<T> response = new Result<>();
        response.setSuccess(true);
        response.setData(data);
        response.setMessage(message);
        return response;
    }

    // =================================== 失败响应 ===================================
    public static <T> Result<T> fail() {
        Result<T> response = new Result<>();
        response.setSuccess(false);
        return response;
    }
    public static <T> Result<T> fail(String errorCode) {
        Result<T> response = new Result<>();
        response.setSuccess(false);
        response.setErrorCode(errorCode);
        return response;
    }

    public static <T> Result<T> fail(String errorCode, String message) {
        Result<T> response = new Result<>();
        response.setSuccess(false);
        response.setErrorCode(errorCode);
        response.setMessage(message);
        return response;
    }

    // 包含异常信息的响应
    public static <T> Result<T> fail(BaseExceptionInterface bizException) {
        Result<T> response = new Result<>();
        response.setSuccess(false);
        response.setMessage(bizException.getMessage());
        response.setErrorCode(bizException.getCode());
        return response;
    }

}
